;; The first three lines of this file were inserted by DrRacket. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname issues) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ()))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Issue 1 ;; Data Definitions that do not capture mutual recursion ;; ;; StringSection ;; ;; A StringSection is one of the following ;; -- (cons String empty) ;; a list whose first element is a string and other element is empty ;; -- (cons string StringSection) ;; represents a list whose first is a string and the other element is a ;; stringsection ;; TEMPLATE: ;; string-section-fn : Section -> ?? ;; (define (string-section-fn ssec) ;; (cond ;; [(empty? (rest ssec) (... (first ssec))] ;; [else (... (first ssec) ;; (string-section-fn (rest ssec)))])) ;; ;; NestedRep ;; ;; A NestedRep (NR) is one of ;; -- empty ; empty ;; -- (cons StringSection NestedRep) ; (cons Section NR) represents a list ;; whose first element is Sexp and whose ;; other elements are represented ;; by ListOfSexp. ;; ;; SHOULD HAVE BEEN: ;; A Section is a ;; (list String ListOfSection) ;; A ListOfSection is one of ;; -- empty ;; -- (cons Section ListOfSection) ;; An Outline is a ListOfSection ;; TEMPLATE: ;; nested-rep-fn : NestedRep -> ?? ;; (define (nested-rep-fn nr) ;; (cond ;; [(empty? nr) (string-section-fn (first nr))] ;; [else (... (section-fn (first nr)) ;; (nested-rep-fn (rest nr)))])) ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Issue 2 ;; Idiosyncratic way of defining lists ;; ;; A FlatRep (FR) is one of ;; -- empty ;; Interpretation: The FlatRep is an empty list ;; -- (cons FlatRepSection empty) ;; Interpretation: A list where the first element is a FlatRepSection ;; and the other element is empty. ;; -- (cons FlatRepSection FlatRep) ;; Interpretation: Represents a list whose first element is ;; FlatRepSection and whose other elements are represented by FlatRep. ;; TEMPLATE: ;; flat-rep-fn : FlatRep -> ?? ;; (define (flat-rep-fn fr) ;; (cond ;; [(empty? fr) empty] ;; [(empty? (rest fr)) (frsection-fn (first nr)] ;; [else (... (frsection-fn (first fr)) ;; (flat-rep-fn (rest fr)))])) ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Issue 3 ;; Invariants that don't really capture anything ;; ;; nested-to-flat : NestedRep -> FlatRep ;; GIVEN: a nested representation of a outline ;; RETURNS: the flat representation of the given outline ;; EXAMPLES: (nested-to-flat outline-list) -> flat-list ;; STRATEGY: Function Composition (define (nested-to-flat nr) (nested-to-flat-from nr LONI)) ;; TESTS: (begin-for-test (check-equal? (nested-to-flat outline-list) flat-list) (check-equal? (nested-to-flat empty-list) empty)) ;; nested-to-flat-from : NestedRep LONI -> FlatRep ;; (ORIGINAL) ;; GIVEN: a nested representation of a list and a list of non neg ;; integers ;; WHERE: LONI is used to convert the first string of nested representation ;; to flat representation ;; RETURNS: the flat representation of the given nestedrep with the help of the ;; list of non-neg integers ;; (BETTER:) ;; GIVEN: a nested representation of a section of some outline and a ;; list of non neg integers ;; WHERE: the LONI represents the section number of that section in ;; the outline. ;; RETURNS: the flat representation of the given section ;; (BETTER:) ;; GIVEN: a nested representation of a section of some outline and a ;; representation of the section number of that section in the outline ;; RETURNS: the flat representation of the given section ;; (ANOTHER ALTERNATIVE) ;; GIVEN: a nested representation of a section of some outline and a ;; representation of a section number ;; RETURNS: the flat representation of the given section, numbered ;; starting at the given section number. ;; EXAMPLES: (nested-to-flat-from outline-list LONI) -> flat-list ;; STRATEGY: Structural Decomposition on nr : NestedRep (define (nested-to-flat-from nr LONI) (cond [(empty? nr) empty] [(empty? (rest nr)) (string-to-flat (first nr) LONI)] [else (append (string-to-flat (first nr) LONI) (nested-to-flat-from (rest nr)(update-loni LONI)))])) ;; TESTS: refer above ;; next-section-number : LONI -> LONI ;; GIVEN: a non-empty list of non neg integers ;; RETURNS: a representation of the next section number at the same level ;; EXAMPLES: (update-loni LONI)->(1) ;; STRATEGY: Structural Decomposition on LONI : ListOfNonNegInt (define (update-loni LONI) (cond [(empty? (rest LONI)) (cons (+ 1 (first LONI))(rest LONI))] [else (cons (+ 1 (first LONI))(rest LONI))])) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Issue 4 ;; No documentation on whether the ListOfNonNegInts in the FlatRep can ;; be any ListOfNonNegInts ;; ;; NonNegIntegerSection ;; ;; A NonNegIntegerSection (NIS) is one of the following ;; -- (cons NonNegInteger empty) ;; First element represent positive integer and other is empty ;; -- (cons NonNegInteger NonNegIntegerSection) ;; First element represent positive integer and other is NonNegIntegerSection ;; TEMPLATE: ;; nisection-fn : NonNegIntegerSection -> ?? ;; (define (nisection-fn nisec) ;; (cond ;; [(empty? (rest sec) (... (first nisec))] ;; [else (... (first nisec) ;; (nisection-fn (rest sec)))])) ;; FlatRepSection ;; ;; A FlatRepSection (FRS) is one of the following ;; -- (list NonNegIntegerSection String) ;; First part of the element is NonNegIntegerSection and other is string ;; TEMPLATE: ;; frsection-fn : Section -> ?? ;; (define (frsection-fn frsec) ;; (... (nisection-fn (first frsec)) ;; (second frsec))) ;; FlatRep ;; ;; A FlatRep (FR) is one of ;; -- (cons FlatRepSection empty) ; (cons FlatRepSection empty) first ;; element is Sexp and other is empty ;; -- (cons FlatRepSection FlatRep) ; (cons FlatRepSection FR) represents a ;; list whose first element is Sexp and ;; whose other elements are represented ;; by ListOfSexp. ;; #| after 3.4.2, the following are the only acceptable possibilities for the next section number: 3.4.3 (same level) 3.4.2.1 (down 1 level) 3.5 (up 1 level) 4. (up 2 levels) [or more if more deeply nested] This list is a legal FlatRep according to his definition (((2 4) "Foo") ((7 8) "Bar") ((1) "Baz")) but is not the representation of any outline #| ;; TEMPLATE: ;; flat-rep-fn : FlatRep -> ?? ;; (define (flat-rep-fn fr) ;; (cond ;; [(empty? (rest fr)) (frsection-fn (first nr)] ;; [else (... (frsection-fn (first fr)) ;; (flat-rep-fn (rest fr)))])) ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;